//
//  PiecesRecordCell.m
//  J智现场
//
//  Created by song on 2018/1/26.
//  Copyright © 2018年 王长飞. All rights reserved.
//

#import "StudyChildCell.h"

@interface StudyChildCell()
{
    UIImageView *pictureImg;
    UILabel *goodsnamelab ;
    UILabel *percent ;
    UILabel *timelab ;
}
@end

@implementation StudyChildCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath
{
    NSString *cellID = [NSString stringWithFormat:@"cellID%zd%zd",indexPath.section,indexPath.row];
    StudyChildCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[StudyChildCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundView = nil ;
        self.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self buildUI];
    }
    return self;
}

- (void)buildUI
{
//    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, orderlab.bottom, SCREEN_WIDTH, 1)];
//    line.backgroundColor = kColorDefultBg;
//    [self addSubview:line];
    
    pictureImg = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 100, 70)];
    [self addSubview:pictureImg];
    
    goodsnamelab = [[UILabel alloc]initWithFrame:CGRectMake(pictureImg.right+10, 15, SCREEN_WIDTH-pictureImg.right-15, 20)];
    goodsnamelab.font = kFontMidden;
    goodsnamelab.textColor = kTitleColor_black;
    [self addSubview:goodsnamelab];
    
    percent = [[UILabel alloc]initWithFrame:CGRectMake(goodsnamelab.left, goodsnamelab.bottom+5, 75, 16)];
    percent.font = [UIFont systemFontOfSize:10];
    percent.textColor = [UIColor whiteColor];
    percent.backgroundColor = UIColorFromRGB1(0xFF9E27);
    [percent setCornerDefaultHalf];
    percent.textAlignment = NSTextAlignmentCenter;
    [percent setHidden:YES];
    [self addSubview:percent];
    
    timelab = [[UILabel alloc]initWithFrame:CGRectMake(goodsnamelab.left, percent.bottom+5, 130, 20)];
    timelab.font = [UIFont systemFontOfSize:12];
    timelab.textColor = kTitleColor_midden;
    [self addSubview:timelab];
    
}

- (void)setModel:(StudyInfoDataList *)model{
    
    _model = model;
    
    [pictureImg sd_setImageWithURL:[NSURL URLWithString:model.indexPic]];
    goodsnamelab.text = model.title;
    timelab.text = model.createTime;
    
    NSString *need = [NSString localizedStringWithFormat:@"%@",model.needStudyTime];
    NSString *already = [NSString localizedStringWithFormat:@"%@",model.alreadyStudyTime];

    if(!model.needStudyTime || ISEMPTY(model.needStudyTime) || ISEqual(need, @"0")){
        [percent setHidden:YES];
    }else{
        [percent setHidden:NO];
        if(ISEqual(need, already)){
            percent.text = @"已完成";
        }else{
            if(ISEqual(already, @"0")){
                percent.text = @"未开始";
                percent.backgroundColor = kTitleColor_light;
            }else{
                percent.text = [NSString stringWithFormat:@"已学习%d%%",[already intValue]*100/[need intValue]];
            }
        }
    }
    
}

@end
